/*
 * @lc app=leetcode.cn id=229 lang=javascript
 *
 * [229] 多数元素 II
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var majorityElement = function (nums) {
  const target = Math.floor(nums.length / 3);

  const objMap = {};
  let rel = [];
  for (const value of nums) {
    objMap[value] = (objMap[value] || 0) + 1;
    if (objMap[value] > target && !rel.includes(value)) {
      rel.push(value);
    }
  }
  return rel;
};
// @lc code=end
